home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include "internal.h"
- #include "userconf.h"
- #include "../paths.h"
- #include "userconf.m"
-
- #define ETC_SHADOW_TMP "/etc/shadow.tmp"
- static USERCONF_HELP_FILE help_shadow ("shadow");
- static CONFIG_FILE f_shadow (ETC_SHADOW,help_shadow,CONFIGF_MANAGED
- ,"root","root",0600);
-
-
-
- /*
- Used when reading the /etc/shadow file
- */
- PUBLIC SHADOW::SHADOW(const char *line)
- {
- char words[9][100];
- user_splitline (line,words);
- name.setfrom (words[0]);
- passwd.setfrom (words[1]);
- last = atoi(words[2]);
- may = atoi(words[3]);
- must = atoi(words[4]);
- warn = atoi(words[5]);
- expire = atoi(words[6]);
- disable = atoi(words[7]);
- reserved.setfrom(words[8]);
- }
- /*
- Used when creating a new record
- */
- PUBLIC SHADOW::SHADOW()
- {
- last = 0;
- may = 0;
- must = 0;
- warn = 0;
- expire = 0;
- disable = 0;
- }
-
- /*
- Return the crypt password field
- */
- PUBLIC const char *SHADOW::getpwd()
- {
- return passwd.get();
- }
- /*
- Write one record of /etc/passwd
- */
- PUBLIC void SHADOW::write(FILE *fout)
- {
- fprintf (fout,"%s:%s:%d:%d:%d:%d:%d:%d:%s\n"
- ,name.get(),passwd.get(),last,may,must,warn,expire,disable
- ,reserved.get());
- }
-
- PUBLIC SHADOWS::SHADOWS()
- {
- /* #Specification: /etc/passwd / strategy
- /etc/shadow is read "by hand" instead of using getpwent() to avoid
- getting all those NIS entries. This is done when editing local
- user account.
- */
- FILE *fin = f_shadow.fopen ("r");
- if (fin != NULL){
- char line[1000];
- while (fgets(line,sizeof(line)-1,fin)!=NULL){
- strip_end (line);
- if (line[0] != '\0'){
- add (new SHADOW(line));
- }
- }
- fclose (fin);
- }
- rstmodified();
- }
- PUBLIC SHADOW *SHADOWS::getitem(int no)
- {
- return (SHADOW*)ARRAY::getitem(no);
- }
- /*
- Get one SHADOW specification of the table or NULL from his login name
- */
- PUBLIC SHADOW *SHADOWS::getitem(const char *name)
- {
- SHADOW *ret = NULL;
- int nbu = getnb();
- for (int i=0; i<nbu; i++){
- SHADOW *usr = getitem(i);
- if (usr->name.cmp(name)==0){
- ret = usr;
- break;
- }
- }
- return ret;
- }
-
- PUBLIC int SHADOWS::write()
- {
- int ret = -1;
- FILE *fout = f_shadow.fopen (ETC_SHADOW_TMP,"w");
- if (fout != NULL){
- int nbu = getnb();
- for (int i=0; i<nbu; i++){
- getitem(i)->write(fout);
- }
- fclose(fout);
- unlink(ETC_SHADOW ".OLD");
- link(ETC_SHADOW, ETC_SHADOW ".OLD");
- unlink(ETC_SHADOW);
- link(ETC_SHADOW_TMP, ETC_SHADOW);
- unlink(ETC_SHADOW_TMP);
- ret = 0;
- }
- return ret;
- }
-
- /*
- Return != 0 if the /etc/shadow file exist
- */
- int shadow_exist ()
- {
- return f_shadow.exist();
- }
-
-
-